//
//  LGBasicSetiingController.m
//  微博
//
//  Created by MS on 15-12-27.
//  Copyright (c) 2015年 MS. All rights reserved.
//

#import "LGBasicSetiingController.h"
#import "BasicSetting.h"
#import "LGBasicCell.h"
@interface LGBasicSetiingController ()

@end

@implementation LGBasicSetiingController

-(NSMutableArray *)groups
{
    if (_groups==nil) {
        _groups = [[NSMutableArray alloc] init];
    }
    return _groups;
}


-(instancetype)init
{
    return [self initWithStyle:UITableViewStyleGrouped
            ];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.backgroundColor = [UIColor colorWithRed:0.83f green:0.83f blue:0.83f alpha:1.00f];
    self.tableView.sectionFooterHeight = 10;
    self.tableView.sectionFooterHeight = 0;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.contentInset = UIEdgeInsetsMake(-20, 0, 0, 0);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

    return self.groups.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    LGGroups * groups = self.groups[section];
    
    return groups.items.count;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    LGGroups * groups = self.groups[indexPath.section];
    LGItem * item = groups.items[indexPath.row];

    LGBasicCell * cell = [LGBasicCell cellWithTableView:tableView];
    
    cell.item =item;
    
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    LGGroups * groups = self.groups[indexPath.section];
    LGItem * item = groups.items[indexPath.row];
    
    if (item.jumpClass) {
        
        UIViewController * vc =  [[item.jumpClass alloc] init];
        vc.title = item.title;
        [self.navigationController pushViewController:vc animated:YES];
    }
    
    if (item.option) {
        item.option(item);
    }
    
    
}


-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
     LGGroups * groups = self.groups[section];
    return groups.headerTitle;
}

-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{
    LGGroups * groups = self.groups[section];
    return groups.footerTitle;
}

@end
